package com.cj.service.impl;

import com.cj.dao.DormitoryStudentDao;
import com.cj.po.Dormitoryinfo;
import com.cj.po.PageInfo;
import com.cj.service.DormitoryStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户Service接口实现类
 */
@Service("dormitoryStudentServiceService")
@Transactional
public class DormitoryStudentServiceImpl implements DormitoryStudentService {

    @Autowired
    private DormitoryStudentDao dormitoryStudentDao;

    @Override
    public PageInfo<Dormitoryinfo> findPageInfo(String s_dormitoryid, Integer pageIndex, Integer pageSize) {
        PageInfo<Dormitoryinfo> dd = new PageInfo<Dormitoryinfo>();
        dd.setPageIndex(pageIndex);
        dd.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = dormitoryStudentDao.totalCount(s_dormitoryid);
        if (totalCount>0){
            dd.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Dormitoryinfo> dormitoryStudentList =dormitoryStudentDao.getDormitoryStudentList(s_dormitoryid, (dd.getPageIndex()-1)*dd.getPageSize(),dd.getPageSize());
            dd.setList(dormitoryStudentList);
        }
        return dd;
    }




}
